<?php
require_once PATH_SITE.'cn/royan/php/utils/writers/WriterUserList.writer.php';
require_once PATH_SITE.'cn/royan/php/utils/writers/WriterUserSimple.writer.php';
require_once PATH_SITE.'cn/royan/php/utils/Logger.util.php';
require_once PATH_SITE.'cn/royan/php/plugins/Plugin.class.php';
require_once PATH_SITE.'cn/royan/php/interfaces/IPlugin.interface.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EnterRoomPlugin
 *
 * @author yanr
 */
class UserEnterRoomPlugin extends Plugin
{
    //put your code here
    const CHANGE        = "RoomUserChange";
    const USER_ENTER    = "UserEnter";
    
    protected $info;
    
    public function __construct( $info )
    {
        parent::__construct();
        Logger::trace( "UserEnterRoomPlugin Build" );
        $this->info = $info;
    }
    
    public function excute()
    {
        Logger::trace( "UserEnterRoomPlugin excute" );
        
        $users = $this->info["room"]->__get("users");
        $writerUserSimple = new WriterUserSimple( $this->info["user"] );
        $data = array( "event"=>    BuilderEvent::SUCCESS,
                       "target"=>   UserEnterRoomParse::USER_ENTER,
                       "user"=>     $users,
                       "data"=>     $writerUserSimple->write() );
        $this->sendNotification( ApplicationFacade::DISPATCH_EVENT, $data );
        
        $writerUserList = new WriterUserList( $this->info["room"] );
        $data = array( "event"=>    BuilderEvent::SUCCESS,
                       "target"=>   UserEnterRoomParse::TYPE,
                       "user"=>     $this->info["user"],
                       "data"=>     $writerUserList->write() );
        $this->sendNotification( ApplicationFacade::DISPATCH_EVENT, $data );
        
        RETURN TRUE;
    }
}

?>
